package com.itheima.d07_lambda_instance_method;

import com.itheima.d04_api_array_sort2.Student;

import java.util.Arrays;

/**
 * 目标：了解静态方法引用，使用场景和语法格式
 */
public class Test {

    public static void main(String[] args) {
        //1.准备测试学生数据
        Student[] students = {
                new Student("小王", 180, 18),
                new Student("小张", 170, 29),
                new Student("小李", 165, 17),
                new Student("小赵", 160, 21)
        };

        //2.排序学生的年纪
        /*Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return CompareHandle.compare(o1,o2);
            }
        });*/

        //lambda简化匿名内部类
        /*Arrays.sort(students, (Student o1, Student o2) ->{
                return o1.getAge()-o2.getAge();
            }
        );*/

        //缺省规则简化lambda
        CompareHandle ch = new CompareHandle();
       /* Arrays.sort(students, ( o1,  o2) -> ch.compare(o1,o2));*/


        //实例方法引用简化lambda
        Arrays.sort(students, ch::compare);


        //3.打印排序结果
        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i]);
        }

    }
}
